package dao;

import domin.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/*
* mybatis中针对,CRUD一共有四个注解
* @Select @Insert @Update @Delete
* */
public interface IUserDao {
    /*
     * 查询所有
     * */
    @Select("select * from user")
    List<User> findAll();

    @Insert("insert into user(username,address,sex,birthday)values(#{username},#{address},#{sex},#{birthday})")
    void saveUser(User user);

    /*
    * 更新用户信息
    * */
    @Update("update user set username=#{username},sex=#{sex},birthday=#{birthday},address=#{address} where id=#{id}")
    void updateUser(User user);

    /*
    * 删除用户
    * */
    @Delete("delete from user where id = #{id}")
    void deleteUser(Integer userId);

    /*
    * 根据ID查询用户
    * */
    @Select("select * from user where id=#{id}")
    User findById(Integer userId);

    /*
    * 根据用户名模糊查询用户
    * */
    @Select("select * from user where username like #{username}")
    List<User> findUserByname(String username);


    /*
    * 根据用户数量
    * */
    @Select("select count(*) from user")
    int findTotalUser();
}
